package com.epam.concurrency.circbuffer;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Arrays;

/**
 * Producer (Writer) for Circular Buffer
 * @author DruidKuma
 * @version 1.0 Build 15.05.2014
 */
public class Producer implements Runnable {

    private int i = 1;
    private final CircularBuffer cb;

    private static final Logger LOGGER = LoggerFactory.getLogger(Producer.class);
    private static final int SLEEPTIME = 500;

    public Producer(CircularBuffer cb) {
        this.cb = cb;
    }

    @Override
    public void run() {
        while(true) {
            cb.add(i);
            i++;
            LOGGER.info(Arrays.toString(cb.getContents()));

            try {
                Thread.sleep(SLEEPTIME);
            } catch (InterruptedException e) {
                LOGGER.error(e.getMessage());
            }
        }
    }

}
